package com.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
 * @author cyf
 * @description
 * @create 2018-09-20 14:57
 **/
public class DynamicProxyFactory{

    private Object target;

    public DynamicProxyFactory(Object object){
        this.target = object;
    }

    public Object getProxyInstance(){
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("这里开始业务代码");
                Object returnValue = method.invoke(target, args);
                System.out.println("这里结束业务代码");
                return returnValue;
            }
        });
    }


}
